package com.sg.business.projectgroup.handler;

import java.util.Map;

import org.eclipse.core.commands.Command;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;

import com.mobnut.db.model.IContext;
import com.mobnut.db.model.PrimaryObject;
import com.sg.business.model.Project;
import com.sg.business.model.ProjectGroup;
import com.sg.widgets.MessageUtil;
import com.sg.widgets.command.AbstractNavigatorHandler;
import com.sg.widgets.part.CurrentAccountContext;
import com.sg.widgets.viewer.ViewerControl;

public class RemoveProjectOfPorjectGroup extends AbstractNavigatorHandler {

	@Override
	protected void execute(PrimaryObject selected, IWorkbenchPart part,
			ViewerControl vc, Command command, Map<String, Object> parameters,
			IStructuredSelection selection) {
		if (selected instanceof Project) {
			try {
				Project project = (Project) selected;
				ProjectGroup projectGroup = (ProjectGroup) vc.getMaster();
				IContext context = new CurrentAccountContext();
				projectGroup.doRemoveProject(context, project.get_id());
			} catch (Exception e) {
				MessageUtil.showToast(e);
			}
		}
	}

}
